<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="p" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/common/plateform/include/common-base.jsp" %>
    <title>接口注册管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

    <!-- top start -->
    <%@include file="/common/plateform/top.jsp" %>
    <!-- top end -->
    <!-- left start -->
    <%@include file="/common/plateform/left.jsp" %>
    <!-- left end-->

    <div class="content-wrapper">
        <!-- Main start -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">

                    <!------搜索  start ------->
                    <div class="box box-info">
                        <!--搜索title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-search"></i> 接口注册搜索</h3>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-minus"></i>
                                </button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove">
                                    <i class="fa fa-times"></i></button>
                            </div>
                        </div>
                        <!--搜索title  end -->
                        <div class="box-body">
                            <form id="searchFrom" class="form-horizontal">
                                <input type="hidden" name="doCode" value="listProtocol"/>
                                <div class="form-group">
                                    <div class="col-sm-2 text_r"><label class="control-label">注册beanId：</label>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="text" class="form-control clean" name="beanId"
                                               value=""/>
                                    </div>
                                    <div class="col-sm-2 text_r"><label class="control-label">注册bean名称：</label>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="text" class="form-control clean"
                                               name="beanName" value=""/>
                                    </div>
                                    <div class="col-sm-4">
                                        <button type="button" class="btn btn-success"
                                                onclick="getTableDatas();"><i
                                                class="fa fa-search"></i> 查询
                                        </button>&nbsp;
                                        <button type="button" class="btn btn-warning"
                                                onclick="cleanData('searchFrom');">重置
                                        </button>
                                        <button onclick="toAdds();" class="btn btn-success"
                                                type="button"><i class="fa fa-plus-circle"></i>增加
                                        </button>
                                        <button onclick="loadCache();" class="btn btn-success"
                                                type="button"><i class="fa fa-plus-circle"></i>刷新缓存
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!------- 搜索 end -------->

                    <!------- 列表 start -------->
                    <div class="box box-success">
                        <div class="box-body">
                            <table id="dataList" class="table table-bordered table-hover">
                                <thead class="bg-success">
                                <tr>
                                    <th>注册bean名称</th>
                                    <th>注册beanId</th>
                                    <th>方法标识</th>
                                    <th>协议</th>
                                    <th>访问地址</th>
                                    <th>端口</th>
                                    <th>版本号</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="dataList-body">
                                </tbody>
                            </table>
                            <center>
                                <ul id="dataList-page"></ul>
                            </center>
                        </div>
                    </div>
                    <!------- 列表 end -------->
                </div>
            </div>
        </section>
        <!-- Main end -->

        <div class="modal fade" id="my_modal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title">
                            <font color="red">信息添加/修改</font>&nbsp;
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="submitForm">
                            <input type="hidden" name="doCode" value="saveProtocol"/>
                            <input type="hidden" id="w_registerId" data-name="registerId"
                                   name="registerId" value=""/>
                            <input type="hidden" id="formToken" name="formToken"
                                   value="${formToken}"/>
                            <div class="box-body" id="submitFormData">
                                <div>
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="tab_1">
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">注册bean名称</label>
                                                <div class="col-sm-8">
                                                    <input type="text" id="beanName"
                                                           data-name="beanName" name="beanName"
                                                           class="form-control clean" required
                                                           placeholder="必填项"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">注册beanId</label>
                                                <div class="col-sm-8">
                                                    <input id="beanId" name="beanId"
                                                           data-name="beanId"
                                                           class="form-control clean"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">方法标识</label>
                                                <div class="col-sm-8">
                                                    <input id="methodName" name="methodName"
                                                           data-name="methodName"
                                                           class="form-control clean"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">协议</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="callType"
                                                            id="callType">
                                                        <option value="">--请选择--</option>
                                                        <option value="http">HTTP协议</option>
                                                        <option value="https">HTTPS协议</option>
                                                        <option value="socket">SOCKET协议</option>
                                                        <option value="webservice">WEBSERVICE协议
                                                        </option>
                                                        <option value="internal">内部</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">访问地址</label>
                                                <div class="col-sm-8">
                                                    <input name="address" id="address"
                                                           data-name="address"
                                                           class="form-control clean" required
                                                           placeholder="必填项"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">端口</label>
                                                <div class="col-sm-8">
                                                    <input id="port" name="port" data-name="port"
                                                           class="form-control clean"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">版本号</label>
                                                <div class="col-sm-8">
                                                    <input id="reserve2" name="reserve2"
                                                           data-name="reserve2"
                                                           class="form-control clean"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">状态</label>
                                                <div class="col-sm-8">
                                                    <input type="radio" name="flag" id="flag_1"
                                                           value="1" checked="checked"/>启用
                                                    <input type="radio" name="flag" id="flag_0"
                                                           value="0"/>停用
                                                </div>
                                            </div>
                                        </div>
                                        <!-- /.tab-pane -->
                                    </div>
                                    <!-- /.tab-content -->
                                </div>
                                <!-- nav-tabs-custom -->
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn btn-success pull-left"
                                        onclick="cannel();">取消
                                </button>
                                <button type="button" class="btn btn-danger pull-right"
                                        onclick="saveItem('submitForm');">提 交
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>

        <script type="text/template" id="dataList-template">
            <? for ( var i = 0; i < rows.length; i++) {?>
            <tr>
                <td style="display:none;"><?=rows[i].registerId?></td>
                <td><?=rows[i].beanName?></td>
                <td><?=rows[i].beanId?></td>
                <td><?=rows[i].methodName?></td>
                <td>
                    <? if(rows[i].callType=='http'){?><font color=blue>http协议</font>
                    <?} else if(rows[i].callType=='https'){?><font color=blue>https协议</font>
                    <?} else if(rows[i].callType=='socket'){?><font color=blue>socket协议</font>
                    <?} else if(rows[i].callType=='webservice'){?><font
                        color=blue>webservice协议</font>
                    <?} else{?><font color=red>内部协议</font><?}?>
                </td>
                <td><?=rows[i].address?></td>
                <td><?=rows[i].port?></td>
                <td><?=rows[i].reserve2?></td>
                <td><? if("0"==rows[i].flag){?><font color=red>停用</font><?}else{?><font color=blue>启用</font><?}?>
                </td>
                <td>
                    <button type="button" class="btn btn-warning btn-xs"
                            onclick="toLoad('<?=rows[i].registerId?>','edit');">修改
                    </button>&nbsp;&nbsp;
                </td>
            </tr>
            <?}?>
        </script>

        <script>
            var clickMenu = "protocol-list";
            myPage = 10;
            searchFormId = "searchFrom";
            tableId = "registerId";
            isShowLog = true;
            dataListId = "dataList";
            $(function () {
                //1、加载分页列表数据
                getTableDatas();
                //alert("11222");
            });

            //读取（查询、编辑）数据
            function toLoad(id, type) {
                var paramLoadData = {"registerId": id};
                $.ajax({
                    type: 'post', url: "${ctx}/info/infoProtocol", dataType: 'json',
                    data: {'registerId': id},
                    success: function (myData) {
                        //console.log(myData);
                        showData(type, myData);
                    }
                });
            }

            function toAdds() {
                $("#my_modal").modal("show");
                initRadio("flag", "1");
                initSelect("callType", "");
            }

            //反显数据
            function showData(type, myData) {
                console.log(myData);
                FormUtil.loadView("", myData);
                if ("view" == type) {
                    $("#my_modal_view").modal("show");
                } else if ("edit" == type) {
                    $("#my_modal").modal("show");
                    initRadio("flag", myData.flag);
                    initSelect("callType", myData.callType);
                }
            }

            function saveItem(formId) {
                $.ajax({
                    type: 'post', url: "${ctx}/info/saveProtocol", dataType: 'json',
                    data: $("#" + formId).serialize(),
                    success: function (myData) {
                        layer.alert(myData.msg, {icon: 1, closeBtn: 0, offset: '220px'});
                        if (myData.flag == 'T') {
                            getTableDatas();
                            layer.alert("操作成功", {icon: 1, closeBtn: 0, offset: '220px'});
                        } else {
                            layer.alert(myData.msg, {icon: 1, closeBtn: 0, offset: '220px'});
                        }
                    }
                });
            }

            function loadCache() {
                $.ajax({
                    type: 'post', url: "${ctx}/info/loadCache", dataType: 'json',
                    success: function (myData) {
                        layer.alert(myData.msg, {icon: 1, closeBtn: 0, offset: '220px'});
                    }
                });
            }

            function getTableDatas() {
                deleteAllRow('dataList');
                $.ajax({
                    type: 'post', url: "${ctx}/info/listProtocol", dataType: 'json',
                    data: $("#" + searchFormId).serialize() + getCurrentPage("${ctx}/info/listProtocol?" + $("#" + searchFormId).serialize(), myPage),
                    success: function (myData) {
                        console.log(myData);
                        var data = baidu.template("dataList-template", eval(myData));
                        $("#dataList-body").html(data);
                        var option = {
                            ele: $("#dataList-page")[0],
                            total: myData.total,
                            fn: getTableDatas,
                            url: common_list_url + "?" + $("#" + searchFormId).serialize()
                        };
                        generatePages(option);
                    }
                });
            }

            function initRadio(elemname, selVl) {
                var myobj = document.getElementsByName(elemname);
                if (myobj == null) return;
                for (var i = 0; i < myobj.length; i++) {
                    if (myobj[i].value == selVl) {
                        myobj[i].checked = "true";
                    }
                }
            }

            function initSelect(elemid, selVl) {
                var myobj = document.getElementById(elemid);
                if (myobj == null) return;
                for (var i = 0; i < myobj.options.length; i++) {
                    if (myobj.options[i].value == selVl) {
                        myobj.selectedIndex = i;
                    }
                }
            }
        </script>
        <script src="${ctx}/js/tools-obj.js"></script>


    </div>
    <!-- /.content-wrapper -->
    <!-- foot start -->
    <%@include file="/common/plateform/foot.jsp" %>
    <!-- foot start -->


</body>


</html>
